package com.laoli.controller;

import com.laoli.entity.UserDTO;
import com.laoli.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * Created with IntelliJ IDEA.
 *
 * @Author: lfw
 * @Date: 2022/04/04/18:57
 * @Description:
 */
@RestController
@RequestMapping("user")
@CrossOrigin
public class AuthorityController {
    @Autowired
    private UserService userService;
    @Autowired
    private RedisTemplate redisTemplate;
    @GetMapping("login")
    public UserDTO login(String phone, String password) {

        return userService.login(phone,password);
    }
    @GetMapping("checkToken")
    public UserDTO checkToken(String token) {
        return userService.checkToken(token);
    }


    @GetMapping("logout")
    public void logout(String token){
        //删除redis中的token
        redisTemplate.delete(token);
    }
}
